<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="仓库管理">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">
    <style type="text/css">
        a{
            color: #01AAED;
            text-decoration: none;
            font-size: 12px;
        }
        a:hover {
            color: #FF5722;
        }

        .readonly{
            background-color: #eeeeee;
        }
        .layui-form-label{
            width: 80px;
            padding: 9px 4px;
        }
        .layui-form-item .layui-input-inline {
            width: 140px;
        }

        .layui-input-block{
            margin-left: 90px;
        }
    </style>
    <script>
        jQuery(function () {
            fixTableOperatorButton();
            ajaxSelect("${baseUrl}organization/store/getStores.action","searchStoreId","全部");
        });

        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;


            renderTable();

            form.on('submit(search)', function (data) {
                var json = data.field;
                table.reload('table',{
                    where: json
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                return false;
            });

            table.on('tool(table)', function (obj) {

                switch(obj.event){
                    case 'delete':
                        del(obj.data);
                        break;
                    case 'edit':
                        openTab("仓库<" + obj.data.name+">编辑","${baseUrl}organization/houseEdit.action?id="+obj.data.id);
                        break;
                };
            });

            //监听事件
            table.on('toolbar(table)', function(obj){
                switch(obj.event){
                    case 'add':
                        openTab("新增仓库","${baseUrl}organization/houseNew.action");
                        break;
                };
            });
        });

        function del(data) {
            layer.confirm('删除仓库《'+data.name+'》?', {icon: 3, title:'删除仓库'}, function(index){
                tipLoad();
                post("${baseUrl}organization/house/delete.action",{id:data.id}, function (resp) {
                    closeAll();
                    if (resp.code == 1){
                        tip("删除成功");
                        renderTable();
                    } else {
                        errTip(resp.msg);
                    }
                });
            });
        }

        function renderTable() {
            layui.use(['openTable'], function () {
                var openTable = layui.openTable;
                openTable.render({
                    id:'table'
                    , elem: '#table'
                    ,toolbar: '#tableToolBar'
                    ,defaultToolbar:[]
                    , url: "${baseUrl}organization/house/getHouses.action?time="+(new Date()).valueOf()
                    , limit: 10
                    , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                        layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                        //,curr: 5 //设定初始在第 5 页
                        ,groups: 5 //只显示 5 个连续页码
                        ,first: false //不显示首页
                        ,last: false //不显示尾页
                    }
                    , done: function(res, curr, count){
                        //console.log(JSON.stringify(res));
                        //渲染完成，初始化操作框提示
                        setTableLineCss("table",res.data, "status", 2, "font-gray-c2c2c2");
                    }
                    , cols: [[
                        {width:70,title:"序号",templet:function (d) {
                            if (d.status == 2){
                                return "<span class='layui-badge layui-bg-gray'>停用</span>";
                            } else {
                                return genTableIndexGreen(d.def, "默认", d);
                            }
                        }},
                        {field: 'id', width: 10, title: 'ID',hide:true},
                        {field: 'no', width: 120, title: '编号',style:"font-size:12px;"},
                        {field: 'name', width: 150, title: '名称',style:"font-size:12px;"},
                        {field: 'houseList',width: 150, title: '所属门店',style:"font-size:12px;",templet:function (d) {
                                return d.store.name;
                            }
                        },
                        {field: 'remark', width: 120, title: '备注',style:"font-size:12px;"},
                        {title: '操作', minWidth: 80, fixed:'right', templet: '#operBar'},
                    ]]

                    //注：展开的列Items
                    , openCols: [
                        {field: 'no', title: '编号'},
                        {field: 'name', title: '名称'},
                        {field: 'contacts', title: '联系人'},
                        {field: 'phone', title: '电话'},
                        {title: '所属门店',
                            templet:function (d) {
                                return genOpenTableContent("所属门店",d.store.name);
                            }
                        },
                        {field: 'email', title: '邮箱',
                            templet:function (d) {
                                return genOpenTableContent("邮箱",d.email == null ? "":d.email);
                            }},
                        {field: 'code', title: '邮编'},
                        {field: 'addres', title: '地址',
                            templet:function (d) {
                                return genOpenTableContent("地址",d.addres == null ? "":d.addres);
                            }
                        },
                        {field: 'remark', title: '备注'},
                    ]
                });
            });
        }

    </script>

</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <input type="hidden" id="companyId" value="${companyId}">

        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">门店</label>
                    <div class="layui-input-inline">
                        <select name="searchStoreId">
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">其他信息</label>
                    <div class="layui-input-inline">
                        <input type="text" name="searchContent" id="searchContent" placeholder="名称 编号 联系人 电话" autocomplete="off" class="layui-input" style="font-size: 12px;">
                    </div>
                </div>

                <div class="layui-inline">
                    <a class="layui-btn" lay-submit="" lay-filter="search">
                        <i class="layui-icon layui-icon-search"></i>
                    </a>
                </div>
                </div>
        </form>

        <div class="horizon-line"></div>

        <table class="layui-hide" id="table" lay-filter="table"></table>

        <script type="text/html" id="tableToolBar">
            <div class="layui-inline">
                <a class="layui-btn" lay-event="add">新增</a>
            </div>
        </script>

        <script type="text/html" id="operBar">
            <a class="layui-btn layui-btn-xs table-operator" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger table-operator" lay-event="delete">删除</a>
        </script>
    </div>
</div>

</body>
<html:loading tip="处理中,请稍后"/>
</html>